Skip to content

fix: reject incorrectly typed response values - #355

Open
whoalin1 wants to merge 1 commit into
openfga:mainfrom
whoalin1:devin/1796123726-strict-response-types
Open

whoalin1 wants to merge 1 commit into
openfga:mainfrom
whoalin1:devin/1796123726-strict-response-types

Conversation

@whoalin1

@whoalin1 whoalin1 commented Dec 1, 2026

Copy link
Copy Markdown

Summary

Fixes #339.

Response deserialization no longer coerces incorrectly typed successful responses into plausible values. In particular, "false" is no longer accepted as a boolean, strings are no longer iterated as lists, and a non-JSON response body is no longer treated as an empty model instance.

The async and sync clients now validate JSON container and primitive types while deserializing documented response shapes and raise FgaValidationException when the shape does not match. Numeric JSON values are still accepted for float fields, while int fields reject booleans and non-integers. Enum-like models without typed object properties retain their existing pass-through behavior.

Validation:

  • uv run pytest -q -m 'not integration' --cov-fail-under 60 --cov openfga_sdk test: 657 passed, 12 deselected, 2 subtests passed; coverage 70.83%
  • uv run ruff check .
  • uv run ruff format --check .: 183 files already formatted

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@whoalin1
whoalin1 requested a review from a team as a code owner December 1, 2026 11:22
@linux-foundation-easycla

Copy link
Copy Markdown

CLA Not Signed

@coderabbitai

coderabbitai Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 49 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4a4ca901-a48b-4d13-ae02-770ffa138ae6
Commits

Reviewing files that changed from the base of the PR and between 60caaa5 and 9287cce.

Files selected for processing: 4

  • openfga_sdk/api_client.py
  • openfga_sdk/sync/api_client.py
  • test/deserialization_test.py
  • test/sync/deserialization_test.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Deserialization still accepts invalid null values and can replace HTTP error exceptions with validation errors, hiding the original status, headers, and body.

2 open issues
What changed in this PR

This PR addresses #339 by tightening response deserialization in both SDK clients, preventing malformed values such as "false" from being coerced into valid authorization results.

Changes:

  • Validate container, primitive, and date-input types, raising FgaValidationException for mismatches.
  • Preserve numeric inputs for float fields and existing enum-like model behavior.
  • Add async and sync regression tests for malformed responses and valid boolean/list responses.
File Description
test/​sync/​deserialization_test.py Adds synchronous response-validation regression tests.
test/​deserialization_test.py Adds asynchronous response-validation regression tests.
openfga_sdk/​sync/​api_client.py Adds strict type checks to synchronous deserialization.
openfga_sdk/​api_client.py Adds matching type checks to asynchronous deserialization.

Review effort: Balanced (adaptive)

Comment thread openfga_sdk/api_client.py
Comment on lines +553 to +556
if not isinstance(data, list):
raise FgaValidationException(
f"Invalid response type for `{klass}`: expected a list, got {type(data).__name__}"
)
Comment thread openfga_sdk/api_client.py
Comment on lines +953 to +956
if not isinstance(data, dict):
raise FgaValidationException(
f"Invalid response type for `{klass.__name__}`: expected a dict, got {type(data).__name__}"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Responses with wrong field types are coerced instead of rejected

2 participants